package com.example.manualexchangemultipledatasourcedemo;

import com.example.manualexchangemultipledatasourcedemo.config.PrimaryDataSourceConfig;
import com.example.manualexchangemultipledatasourcedemo.config.SecondaryDataSourceConfig;
import com.example.manualexchangemultipledatasourcedemo.jobs.BackDataJob;
import org.quartz.*;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@SpringBootApplication
@EnableConfigurationProperties(value = {
                PrimaryDataSourceConfig.PrimaryDataSourceProperties.class,
                SecondaryDataSourceConfig.SecondaryDataSourceProperties.class
        })
public class ManualExchangeMultipleDatasourceDemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(ManualExchangeMultipleDatasourceDemoApplication.class, args);
    }


    /**
     * 将 AuditLogDataBackUpJob 注册到容器中
     *
     * @return
     */
    @Bean
    public JobDetail ActualJobDetail() {
        return JobBuilder.newJob(BackDataJob.class).withIdentity("BackDataJob").storeDurably().build();
    }
    @Bean
    public Trigger ActualTrigger() {
        // 每分钟执行一次
        CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule("0 0/1 * * * ? ");
        return TriggerBuilder.newTrigger().forJob(ActualJobDetail()).withIdentity("BackDataTrigger").withSchedule(cronScheduleBuilder).build();
    }

}
